<?php
class Profile extends CActiveRecord{
    public $birthdayyyyy;
    public $birthdaymm;
    public $birthdaydd;
    public static function model($className = __CLASS__) {
        parent::model($className);
    }
    public function tableName() {
        parent::tableName();
        return 'profile';
    }
    public function relations() {
        parent::relations();
        return array(
            'user'=>  array(self::HAS_ONE,'User','id'),
        );
    }
    public function rules() {
        parent::rules();
        return array(
            array('aliasname','required'),
            array('birthdayyyyy,birthdaymm,birthdaydd','checkBirthday'),
            array('sex,birthday,introduction','safe'),
        );
    }
    public function checkBirthday($attribute,$params){
        if($this->birthdayyyyy!==''||$this->birthdaymm!==''||$this->birthdaydd!==''){
           if($this->birthdayyyyy===''||$this->birthdaymm===''||$this->birthdaydd===''){
               if(!isset($this->errors['birthday'])){
                   $this->addError('birthday', '生年月日を入力してください。');
               }
           }
        }
    }
    public function attributeLabels() {
        parent::attributeLabels();
        return array(
            'aliasname'=>'ネーム',
            'sex'=>'性別',
            'birthday'=>'生年月日',
            'birthdayyyyy'=>'年',
            'birthdaymm'=>'月',
            'birthdaydd'=>'日',
            'introduction'=>'紹介',
        );
    }
    public function formatBirthday(){
        $this->birthday = $this->birthdayyyyy.sprintf('%02d', $this->birthdaymm).sprintf('%02d', $this->birthdaydd);
    }
    
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
